package com.mzy.datepackage.M2022.July.tweight;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/7/28 13:22
 * @Version 1.0
 */
public class Foo {
    static long count = 10_0000_0000L;

    public static void main(String[] args) throws Exception{
        Bar[] bars1 = {new Bar(),new Bar()};
        Bar[] bars2 = {new Bar2(),new Bar2()};
        long start = System.currentTimeMillis();
        a(bars1);
        long end = System.currentTimeMillis();
        System.out.println("bars1用时：" + (end-start));

        start= System.currentTimeMillis();
        a(bars2);
        end = System.currentTimeMillis();
        System.out.println("bars2用时：" + (end-start));

    }


    static void a(Bar[] bar) throws Exception{
        CountDownLatch latch = new CountDownLatch(2);
        new Thread(()->{
            for (long i = 0; i < count; i++) {
                bar[0].l = i;
            }
            latch.countDown();
        }).start();
        new Thread(()->{
            for (long i = 0; i < count; i++) {
                bar[1].l = i;
            }
            latch.countDown();
        }).start();
        latch.await();
    }




}

class Bar{
    volatile long l;
}

class Bar2 extends Bar{
    long l1,l2,l3,l4,l5,l6,l7;
}